from django.db import models
from db.AbstractModel import AbstractModel


# 订单商品详情  可能随着时间变更
class GoodsDetail(AbstractModel):
    goods_name = models.CharField(max_length=50, verbose_name='商品名')  # 商品名字
    goods_price = models.IntegerField(verbose_name='商品价格')  # 商品价格
    goods_img = models.ImageField(verbose_name='商品图片')  # 商品图片
    goods_num = models.IntegerField(verbose_name='商品数量')  # 商品数量
    goods_unit = models.CharField(max_length=10, verbose_name='商品单位')  # 商品单位
    goods_order = models.ForeignKey('Order', verbose_name='所属订单')  # 订单商品所属订单

    def __str__(self):
        return 'GoodsDetail[goods_name=%s, goods_price=%s, goods_img=%s, goods_num=%s, goods_unit=%s, goods_order=%s]' % (
            self.goods_name, self.goods_price, self.img, self.goods_num, self.goods_unit, self.goods_order)


# 订单的基本信息表
class Order(AbstractModel):
    status = (
        (1, '待付款'),
        (2, '待发货'),
        (3, '待收货'),
        (4, '已完成'),
    )
    pay = (
        (1, '货到付款'),
        (2, '微信支付'),
        (3, '支付宝支付'),
        (4, '银联支付'),
    )
    order_number = models.CharField(max_length=50, verbose_name='订单编号')  # 订单编号
    order_status = models.SmallIntegerField(choices=status, default=1, verbose_name='订单状态')  # 订单状态
    order_recv = models.CharField(max_length=20, verbose_name='订单收货人')  # 订单收货人
    order_addr = models.CharField(max_length=50, verbose_name='订单收货地址')  # 订单收货地址
    order_tele = models.CharField(max_length=11, verbose_name='订单收货人')  # 收货人电话
    order_user = models.ForeignKey('users.User', verbose_name='所属顾客')  # 订单所属用户
    order_pay = models.SmallIntegerField(choices=pay, default=1, verbose_name='付款方式')  # 付款方式

    def __str__(self):
        return 'Order[order_number=%s, order_status=%s, order_recv=%s, order_addr=%s, order_tele=%s, order_user=%s, order_pay=%s]' % (
            self.order_number, self.order_status, self.order_recv, self.order_addr, self.order_tele, self.order_user,
            self.order_pay)
